package priv.pront.code.national.acwing.graph;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-27 22:12
 */
public class Acwing1127_香甜的黄油 {

    static int n, p, m, idx, ans = (int) 1e9, INF = (int) 1e9;
    static int[] id, h, ne, e, w, dist;
    static boolean[] st;
    static Queue<Integer> queue = new LinkedList<>();
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt(); p = scanner.nextInt(); m = scanner.nextInt();
        id = new int[n + 10];
        h = new int[p + 10];
        e = new int[2 * m + 10];
        ne = new int[2 * m + 10];
        w = new int[2 * m + 10];
        Arrays.fill(h, -1);
        for(int i = 0; i < n; i++) id[i] = scanner.nextInt();

        for(int i = 1; i <= m; i++){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            add(a, b, c); add(b, a, c);
        }

        for(int i = 1; i <= p; i++){
            ans = Math.min(ans, spfa(i));
        }
        System.out.println(ans);
    }

    private static int spfa(int u){
        dist = new int[p + 10];
        st = new boolean[p + 10];
        Arrays.fill(dist, INF);
        dist[u] = 0;
        st[u] = true;
        queue.add(u);
        while(!queue.isEmpty()){
            int cur = queue.poll();
            st[cur] = false;
            for(int i = h[cur]; i != -1; i = ne[i]){
                int j = e[i];
                if(dist[j] > dist[cur] + w[i]){
                    dist[j] = dist[cur] + w[i];
                    if(!st[j]){
                        queue.add(j);
                        st[j] = true;
                    }
                }
            }
        }
        int res = 0;
        for(int i = 0; i < n; i++){
            int j = id[i];
            if(dist[j] == INF) return INF;
            res += dist[j];
        }
        return res;

    }

    private static void add(int a, int b, int c){
        e[idx] = b; ne[idx] = h[a]; w[idx] = c; h[a] = idx++;
    }
}
